package Code;


import java.util.Random;

/*
需求：定义方法实现随机产生一个5位的验证码
验证码格式：长度大于5，前四位是大写字母或小写字母，最后一位是数字
 */
public class Test3 {
    public static void main(String[] args) {
        Random random = new Random();
        //验证码
        String verificationCode = "";

        char[] word = Word();
        for (int i = 0; i < 4; i++) {
            verificationCode += Extract(word);
        }

        int number = random.nextInt(10);
        System.out.println(verificationCode+number);

    }

    //转换
    public static char[] Word() {
        //创建大小写字母数组
        char[] word = new char[52];
        //定义索引
        int index = 0;

        //大写字母的ascll为65-90,小写字母为97-122
        for (int i = 65; i <= 122; i++) {
            if (i>=97 || i<=90) {
                word[index] = (char) (i);
                index++;
            }
        }
        return word;
    }


    public static char Extract(char[] arr) {
        Random random = new Random();
        int index = random.nextInt(arr.length);

        return arr[index];
    }
}
